package com.enen.demo.service.impl;

import com.enen.demo.bean.Article;
import com.enen.demo.dao.ArticleDao;
import com.enen.demo.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImpl implements IArticleService {
    @Autowired
    private ArticleDao articleDao;

    @Override
    public void saveOrUpdate(Article article) {
        if(article.getId()==null){
            articleDao.save(article);
        }else {
            articleDao.update(article);
        }
    }

    @Override
    public List<Article> findAll() {
        return articleDao.selectAll();
    }

    @Override
    public Article findArticleById(long id) {
        return articleDao.selectArticleById(id);
    }

    @Override
    public void removeArticle(long id) {
        articleDao.delete(id);
    }
}
